package com.xiaolin.spring.annotation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.Nullable;

/**
 * @ClassName ADemoTest
 * @Description TODO
 * @Detail 基于注解的配置
 * @Author MyPC
 * @Date 2020/10/27
 * @Version 1.0
 */
public class ADemoTest {

    private ABean aBean;
    private BBean bBean;
    //作用在成员变量
    @Autowired
    private CBean cBean;


    /**
     *
     * @Autowired  作用在setter方法上
     *              required=false 属性表示就算ABean在容器中找不到，也不会报错，跟@Nullable（任何包中的@Nullable都可以） 注解相同的效果
     * @param aBean
     */
    @Autowired(required = false)
    public void setMovie(ABean aBean) {
        this.aBean = aBean;
    }
    public ADemoTest(){

    }

    /**
     * @Autowired 作用在构造方法上用于方法参数的注入
     * @param bBean
     */
    @Autowired
    public ADemoTest(@Nullable BBean bBean){
        this.bBean=bBean;
    }

    public static void main(String[] args) {
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("a-demo-test.xml");
        ADemoTest ad = applicationContext.getBean("ad", ADemoTest.class);
        System.out.println(ad.aBean);
        System.out.println(ad.bBean);
        System.out.println(ad.cBean);
    }
}
